﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace ns
{
    public class UIPopUpText : MonoBehaviour
    {
        public Text normalText;
        public Text critText;
        public Text healText;
        public float floatTime = 0.5f;

        public void InitPopUp(PopUpType type ,float number ,bool isCrit)
        {
            string text = number.ToString("0"); //整数
            normalText = text;
            critText = text;
            healText = text;

            normalText.enabled = !isCrit && number < 0;
            critText.enabled = isCrit && number < 0;
            healText.enabled = number > 0;

            float time = Random.Range(0, 0.5f) + floatTime;
            float height = Random.Range(0.5f,1f);
            float disperse = Random.Range(-0.5f,0.5f); //离散
            disperse += Mathf.Sign(disperse) * 0.3f; //返回 1 -1 0
            //需要下载插件LeanTween
            LeanTween.moveX(this.gameObject ,this.transform.position.x+disperse,time);
            LeanTween.movez(this.gameObject, this.transform.position.z + disperse, time);
            LeanTween.moveY(this.gameObject, this.transform.position.y + height, time).setEaseOutBack().setDestroyOnComplete(true);

        }

    }
}




